/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import model.Usuario;
import model.Amigo;
import model.Participante;
import model.Viaje;
import java.util.List;
import org.springframework.beans.support.PagedListHolder;
import service.UsuarioService;
import service.amigoService;
import service.ParticipanteService;
import service.ViajeService;
import funcion.enviarMail;
import org.apache.log4j.Level;
import org.apache.log4j.xml.DOMConfigurator;

/**
 *
 * @author Geral Zerap
 * @author Fatima Pestana
 */
public class RechazoViaje extends AbstractCommandController {

    private UsuarioService usuarioService;
    private ParticipanteService participanteService;
    private static Logger loggers = null;
    private ViajeService viajeService;

    public void setViajeService(ViajeService viajeService) {
        this.viajeService = viajeService;
    }

    public void setParticipanteService(ParticipanteService participanteService) {
        this.participanteService = participanteService;
    }

    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

    public RechazoViaje() {
        this.setCommandClass(Usuario.class);
        loggers = Logger.getLogger(Usuario.class.getName());
        loggers.setLevel(Level.ALL);
        DOMConfigurator.configure("C:/Documents and Settings/Administrador/Escritorio/HayTour - Repositorio/hayTourViajes/src/java/main/resources/log4j.xml");

    }

    protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object form, BindException errors) throws Exception {
        Map model = new HashMap();

        Usuario user1;
        List par;
        par = participanteService.getMisViajesPar2(Long.parseLong(request.getParameter("ux")), Long.parseLong(request.getParameter("mv")));

        Participante parte;

        parte = (Participante) par.get(0);

        participanteService.deleteParticipante(parte.getIdParticipa());
        System.out.println(request.getParameter("ux"));

        user1 = (Usuario) usuarioService.getUsuario(Long.parseLong(request.getParameter("ux")));
        List Viajes;
        Viajes = viajeService.listdeMisViajes(user1.getIdUsuario());

        request.getSession().setAttribute("usuarioList", null);
        model.put("title", "MODIFICAR DATOS");
        model.put("viaje", Viajes);
        model.put("usuario", user1);
        return new ModelAndView("perfilUsuario", model);

    }
}
